import { apiGet, apiPost, apiPut, apiDelete } from './client'

export interface Department {
  id?: number
  code?: string
  name?: string
}

type BoPage<T> = { pageNum: number; pageSize: number; total: number; pages: number; list: T[] }

export async function listDepartments(params: { keyword?: string; pageNum: number; pageSize: number }) {
  const page = await apiGet<BoPage<Department>>('/api/grades/departments/page', params)
  return { items: page.list || [], total: page.total || 0 }
}

export async function getDepartment(id: number) {
  return apiGet<Department>(`/api/grades/departments/${id}`)
}

export async function createDepartment(dept: Department) {
  return apiPost<Department>('/api/grades/departments', dept)
}

export async function updateDepartment(id: number, dept: Department) {
  return apiPut<Department>(`/api/grades/departments/${id}`, dept)
}

export async function deleteDepartment(id: number) {
  return apiDelete<string>(`/api/grades/departments/${id}`)
}